﻿BEGIN WORK;
	SET SESSION AUTHORIZATION 'notifier';
----------------Dia da semana-----------------------------------------------------------------ok
	CREATE TABLE dia_semana (
	diasemana VARCHAR(13),
	CONSTRAINT pk_diasemana PRIMARY KEY (diasemana)
	);
	ALTER TABLE dia_semana OWNER TO notifier;
	GRANT ALL ON TABLE dia_semana TO notifier;
	
----------------Hora--------------------------------------------------------------------------ok
	CREATE TABLE hora (
	hora VARCHAR(2),
	CONSTRAINT pk_hora PRIMARY KEY (hora)
	);
	ALTER TABLE hora OWNER TO notifier;
	GRANT ALL ON TABLE hora TO notifier;

----------------Minuto--------------------------------------------------------------------------ok
	CREATE TABLE minuto (
	minuto VARCHAR(2),
	CONSTRAINT pk_minuto PRIMARY KEY (minuto)
	);
	ALTER TABLE minuto OWNER TO notifier;
	GRANT ALL ON TABLE minuto TO notifier;

----------------Horario--------------------------------------------------------------------------ok
	CREATE TABLE Horario(
	idHorario SERIAL,
	Hora_Hora VARCHAR(2),
	Minuto_Minuto VARCHAR(2),
	Dia_semana_diaSemana VARCHAR(13),
	PRIMARY KEY(idHorario)
	);
	ALTER TABLE Horario OWNER TO notifier;
	GRANT ALL ON TABLE Horario TO notifier;

----------------Predio--------------------------------------------------------------------------ok
	CREATE TABLE predio (
	descricao varchar(20),
	CONSTRAINT pk_idpredio PRIMARY KEY (descricao)
	);
	ALTER TABLE predio OWNER TO notifier;
	GRANT ALL ON TABLE predio TO notifier;

----------------Setor--------------------------------------------------------------------------ok
	CREATE TABLE setor (
	descricao varchar(20),
	CONSTRAINT pk_idsetor PRIMARY KEY (descricao)
	);
	ALTER TABLE setor OWNER TO notifier;
	GRANT ALL ON TABLE setor TO notifier;

----------------Sala--------------------------------------------------------------------------ok
	CREATE TABLE sala (
	descricao varchar(3),
	CONSTRAINT pk_idsala PRIMARY KEY (descricao)
	);
	ALTER TABLE sala OWNER TO notifier;
	GRANT ALL ON TABLE sala TO notifier;

----------------Localização--------------------------------------------------------------------------ok
	CREATE TABLE localizacao (
	idLocalizacao SERIAL,
	predio_descricao varchar(20),
	setor_descricao varchar(20),
	sala_descricao varchar(3),
	CONSTRAINT pk_localizacao PRIMARY KEY (idLocalizacao)
	);
	ALTER TABLE localizacao OWNER TO notifier;
	GRANT ALL ON TABLE localizacao TO notifier;

----------------Aula--------------------------------------------------------------------------ok
	CREATE TABLE Aula (
	Localizacao_idLocalizacao INTEGER,
  	Horario_idHorario INTEGER,
  	Turma_Periodo_periodo VARCHAR(6),
  	Turma_codTurma VARCHAR(3),
  	Turma_Disciplina_codDisciplina VARCHAR(6),
	aula_duracao VARCHAR NOT NULL,
	CONSTRAINT pk_aula PRIMARY KEY (Localizacao_idLocalizacao, Horario_idHorario)
	);
	ALTER TABLE aula OWNER TO notifier;
	GRANT ALL ON TABLE aula TO notifier;

----------------Turma--------------------------------------------------------------------------ok
	CREATE TABLE turma (
	disciplina_coddisciplina VARCHAR(6),
	codturma VARCHAR(3),
	periodo_periodo VARCHAR(6),
	docente_matriculadoc VARCHAR(9),
	CONSTRAINT pk_codturma PRIMARY KEY (disciplina_coddisciplina, codturma, periodo_periodo)
	);
	ALTER TABLE turma OWNER TO notifier;
	GRANT ALL ON TABLE turma TO notifier;

----------------Disciplina--------------------------------------------------------------------------ok
	CREATE TABLE disciplina (
	coddisciplina varchar(6),
	departamento_codigodep VARCHAR(4),
	descricao varchar(45),
	CONSTRAINT pk_coddisciplina PRIMARY KEY (coddisciplina)
	);
	ALTER TABLE disciplina OWNER TO notifier;
	GRANT ALL ON TABLE disciplina TO notifier;
	
----------------Usuario--------------------------------------------------------------------------ok
	CREATE TABLE usuario (
	usrlogin varchar(20),
	senha VARCHAR(524),
	grupo_grupo VARCHAR(13),
	CONSTRAINT pk_id PRIMARY KEY (usrlogin)
	);
	ALTER TABLE usuario OWNER TO notifier;
	GRANT ALL ON TABLE usuario TO notifier;
----------------Docente--------------------------------------------------------------------------ok
	CREATE TABLE docente (
	matriculadoc VARCHAR(9),
	usuario_usrlogin VARCHAR(20),
	departamento_codigodep VARCHAR(4),
	nome varchar(50),
        email varchar(50),
	CONSTRAINT pk_matriculadoc PRIMARY KEY (matriculadoc)
	);
	ALTER TABLE docente OWNER TO notifier;
	GRANT ALL ON TABLE docente TO notifier;

----------------Departamento--------------------------------------------------------------------------ok
	CREATE TABLE departamento (
	codigodep varchar(4),
	sigla varchar(4),
	descricao varchar(45),
	CONSTRAINT pk_codigodep PRIMARY KEY (codigodep)
	);
	ALTER TABLE departamento OWNER TO notifier;
	GRANT ALL ON TABLE departamento TO notifier;

----------------Periodo--------------------------------------------------------------------------ok
	CREATE TABLE periodo (
	periodo VARCHAR(6),
	CONSTRAINT pk_periodo PRIMARY KEY (periodo)
	);
	ALTER TABLE periodo OWNER TO notifier;
	GRANT ALL ON TABLE periodo TO notifier;

----------------Nivel--------------------------------------------------------------------------ok
	CREATE TABLE nivel (
	nivel varchar(15),
	CONSTRAINT pk_nivel PRIMARY KEY (nivel)
	);
	ALTER TABLE nivel OWNER TO notifier;
	GRANT ALL ON TABLE nivel TO notifier;

----------------Curso--------------------------------------------------------------------------ok
	CREATE TABLE curso (
	codigocurso VARCHAR(3),
	nivel_nivel varchar(15),
	descricao varchar(50),
	CONSTRAINT pk_curso PRIMARY KEY(codigocurso)
	);
	ALTER TABLE curso OWNER TO notifier;
	GRANT ALL ON TABLE curso TO notifier;

----------------Curso pertence a departamento--------------------------------------------------------------------------OK
	CREATE TABLE curso_has_departamento (
	curso_codigocurso VARCHAR(3),
	departamento_codigodep VARCHAR(4),
	CONSTRAINT pk_departamento_has_curso PRIMARY KEY(curso_codigocurso, departamento_codigodep)
	);
	ALTER TABLE curso_has_departamento OWNER TO notifier;
	GRANT ALL ON TABLE curso_has_departamento TO notifier;

----------------Grupo de usuarios--------------------------------------------------------------------------
	CREATE TABLE grupo(
        grupo VARCHAR(13),
	CONSTRAINT pk_grupo PRIMARY KEY (grupo)
	);
	ALTER TABLE grupo OWNER TO notifier;
	GRANT ALL ON TABLE grupo TO notifier;
	
------------------------Funcionario------------------------------------------------------------
	CREATE TABLE Funcionario (
	codFuncionario VARCHAR(9),
	Usuario_usrlogin VARCHAR(20),
	Nome VARCHAR(50),
	Cargo VARCHAR(50),
        email varchar(50),
	CONSTRAINT pk_funcionario PRIMARY KEY(codFuncionario)
	);
	ALTER TABLE Funcionario OWNER TO notifier;
	GRANT ALL ON TABLE Funcionario TO notifier;
------------------------Tecnologia do celular------------------------------------------------
	CREATE TABLE Tec_cel(
	tecnologia VARCHAR(10),
	CONSTRAINT pk_tec_cel PRIMARY KEY(tecnologia));
	ALTER TABLE Tec_cel OWNER TO notifier;
	GRANT ALL ON TABLE Tec_cel TO notifier;
------------------------Discente------------------------------------------------------------
	CREATE TABLE discente (
	matriculadisc VARCHAR(9),
	usuario_usrlogin VARCHAR(20),	
	nome varchar(50),
	curso_codigocurso VARCHAR(3),
	ddd VARCHAR(2),
	num VARCHAR(8),
	tec_Cel_tecnologia VARCHAR(10),
        email varchar(50),
	CONSTRAINT pk_matriculadisc PRIMARY KEY (matriculadisc)
	);
	ALTER TABLE discente OWNER TO notifier;
	GRANT ALL ON TABLE discente TO notifier;

----------------Modo de envio--------------------------------------------------------------------------
	CREATE TABLE modo_envio (
	idmodo_envio SERIAL,
	descricao varchar(20),
	CONSTRAINT pk_idmodo_envio PRIMARY KEY (idmodo_envio)
	);
	ALTER TABLE modo_envio OWNER TO notifier;
	GRANT ALL ON TABLE modo_envio TO notifier;

----------------Tipo de notificação--------------------------------------------------------------------------
	CREATE TABLE tipo_notif (
	tiponotificacao varchar(15),
	modo_envio_idmodo_envio INTEGER,
	CONSTRAINT pk_tiponotificacao PRIMARY KEY (tiponotificacao)
	);
	ALTER TABLE tipo_notif OWNER TO notifier;
	GRANT ALL ON TABLE tipo_notif TO notifier;
	
----------------Preferencia--------------------------------------------------------------------------
	CREATE TABLE preferencia (
	discente_matriculadisc VARCHAR(9),
	tipo_notif_tiponotificacao VARCHAR(15),
	CONSTRAINT pk_preferencia PRIMARY KEY (discente_matriculadisc, tipo_notif_tiponotificacao)
	);
	ALTER TABLE preferencia OWNER TO notifier;
	GRANT ALL ON TABLE preferencia TO notifier;

----------------Notificação--------------------------------------------------------------------------
	CREATE TABLE notificacao (
	idnotificacao SERIAL,
	discente_matriculadisc VARCHAR(9),
	tipo_notif_tiponotificacao VARCHAR(15),
	docente_matriculadoc VARCHAR(9),
	texto VARCHAR(160),
	CONSTRAINT pk_idnotificacao PRIMARY KEY (idnotificacao)
	);
	ALTER TABLE notificacao OWNER TO notifier;
	GRANT ALL ON TABLE notificacao TO notifier;

----------------Histórico de notificação--------------------------------------------------------------------------
	CREATE TABLE historico_n (
	idnotificacao INTEGER,
	discente_matriculadisc VARCHAR(9),
	tipo_notif_tiponotificacao VARCHAR(15),
	docente_matriculadoc VARCHAR(9),
	texto VARCHAR(160),
	CONSTRAINT pk_historico_idnotificacao PRIMARY KEY (idnotificacao)
	);
	ALTER TABLE historico_n OWNER TO notifier;
	GRANT ALL ON TABLE historico_n TO notifier;

----------------Turma possui discentes--------------------------------------------------------------------------
	CREATE TABLE turma_has_discente (
	idTurma_has_discente SERIAL,
	turma_periodo_periodo VARCHAR(6),
	turma_codturma VARCHAR(3),
	turma_disciplina_coddisciplina VARCHAR(6),
	discente_matriculadisc VARCHAR(9),
	CONSTRAINT pk_turma_has_discente PRIMARY KEY (idTurma_has_discente)
	);
	ALTER TABLE turma_has_discente OWNER TO notifier;
	GRANT ALL ON TABLE turma_has_discente TO notifier;

----------------Dia--------------------------------------------------------------------------
	CREATE TABLE dia (
	dia VARCHAR(2),
	CONSTRAINT pk_dia PRIMARY KEY (dia)
	);
	ALTER TABLE dia OWNER TO notifier;
	GRANT ALL ON TABLE dia TO notifier;

----------------Mês--------------------------------------------------------------------------
	CREATE TABLE mes (
	mes VARCHAR(9),
	CONSTRAINT pk_mes PRIMARY KEY (mes)
	);
	ALTER TABLE mes OWNER TO notifier;
	GRANT ALL ON TABLE mes TO notifier;

----------------Ano--------------------------------------------------------------------------
	CREATE TABLE ano (
	ano VARCHAR(4),
	CONSTRAINT pk_ano PRIMARY KEY (ano)
	);
	ALTER TABLE ano OWNER TO notifier;
	GRANT ALL ON TABLE ano TO notifier;

----------------Avaliacao--------------------------------------------------------------------------
	CREATE TABLE avaliacao (
	idTurma_x_discente INTEGER,
	unidade INTEGER,
	nota REAL,
	CONSTRAINT pk_unidade PRIMARY KEY (idTurma_x_discente, unidade)
	);
	ALTER TABLE avaliacao OWNER TO notifier;
	GRANT ALL ON TABLE avaliacao TO notifier;

----------------falta--------------------------------------------------------------------------
	CREATE TABLE falta (
	idTurma_x_discente INTEGER,
	dia_dia VARCHAR(2),
	mes_mes VARCHAR(9),
	ano_ano VARCHAR(4),
	CONSTRAINT pk_falta PRIMARY KEY (idTurma_x_discente, dia_dia, mes_mes, ano_ano)
	);
	ALTER TABLE falta OWNER TO notifier;
	GRANT ALL ON TABLE falta TO notifier;

----------------------------------------------------------------------------------------------------------------------------
--------------------------------Criação das chaves estrangeiras e de restrições UNIQUE--------------------------------------
----------------------------------------------------------------------------------------------------------------------------
	
	------------------Horario--------------------------------------------------

	ALTER TABLE ONLY horario ADD CONSTRAINT fk_hora_hora FOREIGN KEY (hora_hora) REFERENCES hora(hora) ON UPDATE RESTRICT ON DELETE RESTRICT;

	ALTER TABLE ONLY horario ADD CONSTRAINT fk_minuto_minuto FOREIGN KEY (minuto_minuto) REFERENCES minuto(minuto) ON UPDATE RESTRICT ON DELETE RESTRICT;

	ALTER TABLE ONLY horario ADD CONSTRAINT fk_dia_Semana_diaSemana FOREIGN KEY (dia_Semana_diaSemana) REFERENCES dia_semana(diaSemana) ON UPDATE RESTRICT ON DELETE RESTRICT;

	ALTER TABLE ONLY horario ADD CONSTRAINT un_horario_x_dia_unique UNIQUE (hora_hora, minuto_minuto, dia_Semana_diaSemana);

	-----------------Localização-------------------------------------------------------

	ALTER TABLE ONLY localizacao ADD CONSTRAINT fk_predio_idpredio FOREIGN KEY (predio_descricao) REFERENCES predio(descricao) ON UPDATE RESTRICT ON DELETE RESTRICT;

	ALTER TABLE ONLY localizacao ADD CONSTRAINT fk_setor_idsetor FOREIGN KEY (setor_descricao) REFERENCES setor(descricao) ON UPDATE RESTRICT ON DELETE RESTRICT;

	ALTER TABLE ONLY localizacao ADD CONSTRAINT fk_sala_idsala FOREIGN KEY (sala_descricao) REFERENCES sala(descricao) ON UPDATE RESTRICT ON DELETE RESTRICT;

	ALTER TABLE ONLY localizacao ADD CONSTRAINT un_localizacaoUnique UNIQUE (predio_descricao, setor_descricao, sala_descricao);

	-----------------Aula-------------------------------------------------------------

	ALTER TABLE ONLY Aula ADD FOREIGN KEY (Localizacao_idLocalizacao) REFERENCES Localizacao (idLocalizacao) ON UPDATE RESTRICT ON DELETE RESTRICT;
	
	ALTER TABLE ONLY Aula ADD FOREIGN KEY (Horario_idHorario) REFERENCES Horario (idHorario) ON UPDATE RESTRICT ON DELETE RESTRICT;

	ALTER TABLE ONLY Aula ADD FOREIGN KEY (Turma_Periodo_periodo, Turma_codTurma, Turma_Disciplina_codDisciplina) REFERENCES Turma (Periodo_periodo, codTurma, Disciplina_codDisciplina) ON UPDATE RESTRICT ON DELETE RESTRICT;

	ALTER TABLE ONLY AULA ADD CONSTRAINT aula_turma_horario UNIQUE (Horario_idHorario, Turma_Periodo_periodo, Turma_codTurma, Turma_Disciplina_codDisciplina);


	-----------------------Turma-------------------------------------------------------
	ALTER TABLE ONLY turma ADD CONSTRAINT fk_disciplina_coddisciplina FOREIGN KEY (disciplina_coddisciplina) REFERENCES disciplina(coddisciplina) ON UPDATE RESTRICT ON DELETE RESTRICT;

	ALTER TABLE ONLY turma ADD CONSTRAINT fk_docente_matriculadoc FOREIGN KEY (docente_matriculadoc) REFERENCES docente(matriculadoc) ON UPDATE RESTRICT ON DELETE RESTRICT;

	ALTER TABLE ONLY turma ADD CONSTRAINT fk_periodo_periodo FOREIGN KEY (periodo_periodo) REFERENCES periodo(periodo) ON UPDATE RESTRICT ON DELETE RESTRICT;

	-----------------------Disciplina--------------------------------------------------

	ALTER TABLE ONLY disciplina ADD CONSTRAINT fk_departamento_codigodep FOREIGN KEY (departamento_codigodep) REFERENCES departamento(codigodep) ON UPDATE RESTRICT ON DELETE RESTRICT;

	-------------------------Docente---------------------------------------------------

	ALTER TABLE ONLY docente ADD CONSTRAINT fk_departamento_codigodep FOREIGN KEY (departamento_codigodep) REFERENCES departamento(codigodep) ON UPDATE RESTRICT ON DELETE RESTRICT;

	ALTER TABLE ONLY docente ADD CONSTRAINT fk_usuario_usrlogin FOREIGN KEY (usuario_usrlogin) REFERENCES usuario(usrlogin) ON UPDATE RESTRICT ON DELETE RESTRICT;

	-------------------------Usuario---------------------------------------------------

	ALTER TABLE ONLY Usuario ADD CONSTRAINT fk_grupo_grupo FOREIGN KEY (grupo_grupo) REFERENCES grupo(grupo) ON UPDATE RESTRICT ON DELETE RESTRICT ;

	-------------------------Departamento---------------------------------------------------

	ALTER TABLE ONLY Departamento ADD CONSTRAINT un_sigla UNIQUE (sigla);

	-----------------------Curso-------------------------------------------------------
	ALTER TABLE ONLY curso ADD CONSTRAINT fk_nivel_nivel FOREIGN KEY (nivel_nivel) REFERENCES nivel(nivel) ON UPDATE 		CASCADE ON DELETE RESTRICT;

	--ALTER TABLE ONLY curso ADD CONSTRAINT un_nivel_x_curso UNIQUE (nivel_nivel, descricao);

	----------------------Curso_has_departamento---------------------------------------

	ALTER TABLE ONLY curso_has_departamento ADD CONSTRAINT fk_curso_codigocurso FOREIGN KEY (curso_codigocurso) 
		REFERENCES curso(codigocurso) ON UPDATE RESTRICT ON DELETE RESTRICT;

	ALTER TABLE ONLY curso_has_departamento ADD CONSTRAINT fk_departamento_codigodep FOREIGN KEY(departamento_codigodep) REFERENCES departamento(codigodep) ON UPDATE RESTRICT ON DELETE RESTRICT;


	------------------------Funcionario------------------------------------------------------------
	ALTER TABLE ONLY Funcionario ADD CONSTRAINT fk_usuario_usrlogin FOREIGN KEY(Usuario_usrlogin) 
	REFERENCES Usuario(usrlogin);


	-------------------------Discente--------------------------------------------------

	ALTER TABLE ONLY discente ADD CONSTRAINT fk_tec_cel_tecnologia FOREIGN KEY (tec_cel_tecnologia)
		REFERENCES tec_cel(tecnologia) ON UPDATE RESTRICT ON DELETE RESTRICT;

	ALTER TABLE ONLY discente ADD CONSTRAINT fk_curso_codigocurso FOREIGN KEY (curso_codigocurso)
		REFERENCES curso(codigocurso) ON UPDATE RESTRICT ON DELETE RESTRICT;

	ALTER TABLE ONLY discente ADD CONSTRAINT fk_usuario_usrlogin FOREIGN KEY (usuario_usrlogin)
		REFERENCES usuario(usrlogin) ON UPDATE RESTRICT ON DELETE RESTRICT;

	ALTER TABLE ONLY discente ADD CONSTRAINT un_celular UNIQUE (ddd, num);
	
	ALTER TABLE ONLY discente ADD CONSTRAINT un_usuario_usrlogin UNIQUE (usuario_usrlogin);
	
	----------------Modo de envio--------------------------------------------------------------------------
	ALTER TABLE ONLY modo_envio ADD CONSTRAINT un_descricao UNIQUE(descricao);

	-----------------------Tipo_notificacao--------------------------------------------
	ALTER TABLE ONLY tipo_notif ADD CONSTRAINT fk_modo_envio_idmodo_envio FOREIGN KEY (modo_envio_idmodo_envio)
		REFERENCES modo_envio(idmodo_envio) ON UPDATE RESTRICT ON DELETE RESTRICT;

	-----------------------Preferencia-------------------------------------------------
	ALTER TABLE ONLY preferencia ADD CONSTRAINT fk_discente_matriculadisc FOREIGN KEY (discente_matriculadisc)
		REFERENCES discente(matriculadisc) ON UPDATE RESTRICT ON DELETE RESTRICT;

	ALTER TABLE ONLY preferencia ADD CONSTRAINT fk_tipo_notif_tiponotificacao FOREIGN KEY (tipo_notif_tiponotificacao)
		REFERENCES tipo_notif(tiponotificacao) ON UPDATE RESTRICT ON DELETE RESTRICT;

	-----------------------Notificacao-------------------------------------------------
	ALTER TABLE ONLY notificacao ADD CONSTRAINT fk_docente_matriculadoc FOREIGN KEY (docente_matriculadoc) REFERENCES docente(matriculadoc) ON UPDATE RESTRICT ON DELETE RESTRICT;

	ALTER TABLE ONLY notificacao ADD CONSTRAINT fk_tipo_notif_tiponotificacao FOREIGN KEY
		(tipo_notif_tiponotificacao) REFERENCES tipo_notif(tiponotificacao) 
		ON UPDATE RESTRICT ON DELETE RESTRICT;

	ALTER TABLE ONLY notificacao ADD CONSTRAINT fk_discente_matriculadisc FOREIGN KEY
		(discente_matriculadisc) REFERENCES discente(matriculadisc) 
		ON UPDATE RESTRICT ON DELETE RESTRICT;

	-----------------------Turma_has_discente------------------------------------------

	ALTER TABLE ONLY turma_has_discente ADD CONSTRAINT fk_turma_disciplina_coddisciplina FOREIGN KEY (turma_disciplina_coddisciplina, turma_codturma, turma_periodo_periodo) REFERENCES turma(disciplina_coddisciplina, codturma, periodo_periodo) ON UPDATE RESTRICT ON DELETE RESTRICT;

	ALTER TABLE ONLY turma_has_discente ADD CONSTRAINT fk_discente_matriculadisc FOREIGN KEY (discente_matriculadisc) REFERENCES discente(matriculadisc) ON UPDATE RESTRICT ON DELETE RESTRICT;

	ALTER TABLE ONLY turma_has_discente ADD CONSTRAINT un_turma_has_discente UNIQUE(turma_codturma, turma_disciplina_coddisciplina, discente_matriculadisc);

	-----------------------Avaliacao------------------------------------------

	ALTER TABLE ONLY Avaliacao ADD CONSTRAINT fk_turma_has_discente_id FOREIGN KEY (idTurma_x_discente)
	REFERENCES turma_has_discente(idTurma_has_discente) ON UPDATE RESTRICT ON DELETE RESTRICT;

	-----------------------Falta------------------------------------------

	ALTER TABLE ONLY Falta ADD CONSTRAINT fk_turma_has_discente_id FOREIGN KEY (idTurma_x_discente)
	REFERENCES turma_has_discente(idTurma_has_discente) ON UPDATE RESTRICT ON DELETE RESTRICT;

	ALTER TABLE ONLY Falta ADD CONSTRAINT fk_dia_dia FOREIGN KEY (dia_dia)
	REFERENCES dia(dia) ON UPDATE RESTRICT ON DELETE RESTRICT;
	
	ALTER TABLE ONLY Falta ADD CONSTRAINT fk_mes_mes FOREIGN KEY (mes_mes)
	REFERENCES mes(mes) ON UPDATE RESTRICT ON DELETE RESTRICT;

	ALTER TABLE ONLY Falta ADD CONSTRAINT fk_ano_ano FOREIGN KEY (ano_ano)
	REFERENCES ano(ano) ON UPDATE RESTRICT ON DELETE RESTRICT;

COMMIT;
